package com.yang.jxj.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yang.jxj.entity.Rules;
import com.yang.jxj.entity.Score;
import com.yang.jxj.entity.Students;
import com.yang.jxj.service.impl.RulesServiceImpl;
import com.yang.jxj.service.impl.ScoreServiceImpl;
import com.yang.jxj.service.impl.StudentsServiceImpl;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;

import java.util.HashMap;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yang
 * @since 2024-06-21
 */
@Controller
@RequestMapping("/api/students")
public class StudentsController {


    @Autowired
    private StudentsServiceImpl stu;
    @Autowired
    private ScoreServiceImpl score;
    @Autowired
    private RulesServiceImpl rules;



    @GetMapping("/message")
    public ResponseEntity<HashMap<String,Object>> test(HttpServletRequest request) {
        HashMap<String,Object> map = new HashMap<>();
        Integer userId = Integer.valueOf(String.valueOf(request.getAttribute("userId"))) ;
        Students stud =  stu.getById(userId);
        QueryWrapper<Rules> wrapper = new QueryWrapper<Rules>();
        wrapper.eq("year", stud.getEnrollmentYear());
        wrapper.eq("grade", stud.getGrade());
        Score byId = score.getById(userId);
        map.put("student", stud);
        map.put("score", byId);
        map.put("rules",rules.getOne(wrapper));
        return ResponseEntity.ok(map);
    }
}
